<template>
  <b-container fluid style="font-size: 0.9rem;">
    <InfoTable ref="InfoTable" :param="param" :location="location" href="branches" :fixed="false">
      <template slot="button-operation">
        <slot name="button-operation"></slot>
      </template>
      <template slot="table-operation" slot-scope="row">
        <slot name="table-operation" :data="row">
          <b-btn variant="outline-primary" style="margin-right:5px;padding:5px;font-size:0.7rem" @click="$router.push('/fault-treatment/fault-anticipatie-model-manger')">修改</b-btn>
          <b-btn variant="outline-primary" style="margin-right:5px;padding:5px;font-size:0.7rem" @click="currentRecord=row,$refs.DeleteModelModal.show()">删除</b-btn>
        </slot>
      </template>
    </InfoTable>
    <b-modal ref="DeleteModelModal" title="模型配置" size="lg">
      <b-container fluid>
        确定删除?
      </b-container>
      <div slot="modal-footer" class="w-100">
        <b-btn size="sm" class="float-right" variant="primary" @click="$refs.DeleteModelModal.hide()">
          返回
        </b-btn>
        <b-btn size="sm" class="float-right" style="margin-right:10px" variant="primary" @click="remove(),$refs.DeleteModelModal.hide()">
          确定
        </b-btn>
      </div>
    </b-modal>
  </b-container>
</template>

<script>
import InfoTable from "components/InfoTable";
import InfoModal from "components/InfoModal.vue";
import {
  baseURL,
  get,
  save,
  associate,
  getAndAssociate,
  remove,
  axios
} from "src/service/api";
export default {
  components: {
    InfoTable,
    InfoModal
  },
  props: ["currentDetail"],
  data() {
    return {
      location: "branches/search/allDetail",
      param: "",
      currentRecord: {}
    };
  },
  methods: {
    info(o, row) {
      console.log(row);
      o.info(row.data);
    },
    remove() {
      remove(this.currentRecord.data.item._links.self.href)
        .then(function(response) {
          if (response.status == "204") {
            console.log("资源删除成功");
          }
          console.log(response);
        })
        .catch(function(error) {
          console.log(error);
        });
      this.$refs.InfoTable.refresh();
    }
  },
  watch: {
    currentDetail: function() {
      let detailId = parseInt(
        this.$refs.InfoTable.getKey(this.currentDetail._links.self.href)
      );
      this.param = "detailId=" + detailId;
    }
  }
};
</script>
<style lang="scss" scoped>
.table th,
.table td {
  vertical-align: middle;
}
.custom-select {
  width: 60px;
  float: left;
}
</style>
